package rauguelu.programaEventos;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import rauguelu.feria.tapas.TapaDetalle;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

public class detalleEvento extends Activity  {


	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.programa_eventos_detalle);
	        
	    	final Intent myIntent = getIntent();
	    	final Bundle myBundle = myIntent.getExtras(); 
	    	final BaseDatosHelper miBBDDHelper = new BaseDatosHelper(this);
	    	
	    	ImageView imagen_evento= (ImageView) findViewById(R.id.imagen_evento); 
	    	TextView dsEvento = (TextView) findViewById(R.id.dsEvento);
	    	TextView dsInfoEvento = (TextView) findViewById(R.id.dsInfoEvento);
			TextView dsDescripcion = (TextView) findViewById(R.id.dsDescripcion);
			TextView horaEventoDetalle = (TextView) findViewById(R.id.horaEventoDetalle);
			final TextView dsCategoriaDetalle = (TextView)findViewById(R.id.dsCategoriaDetalle);
			//TextView dsDescripcion = (TextView) findViewById(R.id.dsDescripcion);
			
			TextView visitarWeb = (TextView)findViewById(R.id.visitarWeb);
			TextView compartirEvento = (TextView)findViewById(R.id.compartirEvento);
			visitarWeb.setText("Ir a Web");
			compartirEvento.setText("Compartir");
		
			
			dsEvento.setText(myBundle.getString("dsEvento"));
			
			Typeface font = Typeface.createFromAsset(getAssets(), "VSVBPSB.TTF");
			Typeface font2= Typeface.createFromAsset(getAssets(), "VSVAB.TTF");
			
		        
			dsInfoEvento.setText(Html.fromHtml("<p style=\"text-align: justify\">"+myBundle.getString("dsGeo")+"</p>"));

			if(myBundle.getString("diaEvento").equals("15/06/2012"))
				horaEventoDetalle.setText("Viernes 15 - " +myBundle.getString("horaEvento"));
			if(myBundle.getString("diaEvento").equals("16/06/2012"))
				horaEventoDetalle.setText("Sabado 16 - " +myBundle.getString("horaEvento"));
			if(myBundle.getString("diaEvento").equals("17/06/2012"))
				horaEventoDetalle.setText("Domingo 17 - " +myBundle.getString("horaEvento"));
			
			dsCategoriaDetalle.setText(myBundle.getString("dsCategoria"));
			dsDescripcion.setText(myBundle.getString("dsDescripcion"));
			
			dsCategoriaDetalle.setTypeface(font);
			dsEvento.setTypeface(font2);
			visitarWeb.setTypeface(font);
			compartirEvento.setTypeface(font);
			final String clase = myBundle.getString("claseOrigen");	
			myBundle.putString("claseOrigen","detalleEvento");
			
			imagen_evento.setImageResource(
	            		this.getResources().getIdentifier(myBundle.getString("dsDatosAux").toString(),
	            				"drawable", this.getPackageName()));
			
			
			compartirEvento.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent share = new Intent(Intent.ACTION_SEND);
	        		 share.setType("image/jpeg"); // might be text, sound, whatever
	        		 FileOutputStream output;
	        		 File imagenEvento=null;
					try {
						output = openFileOutput("evento.jpeg",MODE_WORLD_READABLE );
					
						
		        		 InputStream inputPrueba = getResources().openRawResource(detalleEvento.this.getResources().getIdentifier(myBundle.getString("dsDatosAux").toString(),
		            				"drawable", detalleEvento.this.getPackageName()));
		        		 byte[] buffer = new byte[128];
		        		 while ( ( inputPrueba.read(buffer) ) != -1  )
		        		 {
		        			 output.write(buffer);
		        			 output.flush();
		        		 }
		        	 
		        	 
		        		 imagenEvento = getFileStreamPath("evento.jpeg");
					} catch (FileNotFoundException e) {
						e.printStackTrace();
					} catch (IOException e) {
						e.printStackTrace();
					}
					
	        		 share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imagenEvento));
	        		 share.putExtra(Intent.EXTRA_TEXT, "¿Quién se apunta a \"" + myBundle.getString("dsEvento") + "\" en el Festival De Los Sentidos? @FdelosSentidos");
	        		 
	        		 startActivity(Intent.createChooser(share, "Compartir evento"));
					
				}
			});
			
			
			 visitarWeb.setOnClickListener(new View.OnClickListener(){
				 public void onClick(View v){
				        Intent intent = new Intent();
				        intent.setAction(Intent.ACTION_VIEW);
				        intent.addCategory(Intent.CATEGORY_BROWSABLE);
				        intent.setData(Uri.parse(myBundle.getString("dsWeb")));
				        startActivity(intent);
				    }
				});
			 
							
	 	}
	 	 	
}